# 邮箱token加密
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings
import logging

logger = logging.getLogger('django')
# 加密方法

def dumps_email_token(token):
    serializer = Serializer(settings.SECRET_KEY, expires_in=3600)

    token_b = serializer.dumps(token)

    return token_b.decode()



# 解密方法

def loads_email_token(token_b):
    serializer = Serializer(settings.SECRET_KEY, expires_in=3600)
    token = serializer.loads(token_b)

    return token




# token验证方法

def token_cleck(token):
    token_dict = loads_email_token(token)
    if not token_dict:
        logger.error('token解密失败')
    return token_dict